//爬取堆糖网站
const puppeteer = require("puppeteer");
const url = "https://www.duitang.com/"
async function run() {
    const browser = await puppeteer.launch()
    const page = await browser.newPage();
    await page.goto(url, {
        waitUntil: 'networkidle2'
    })
    await page.waitFor(2000)
    await page.hover(".dynamic-feed-item")
    let res = await page.evaluate(() => {
        var $ = window.jQuery
        var items = $(".dynamic-feed-item")
        // .user-info .avatar  --src属性 $(".user-info .avatar").attr("src")
        // .user-info .username   $(".user-info .username").html()
        var links = [];
        if(items.length>0){
            items.each((index,item)=>{
                let avatar = $(item).find(".user-info .avatar").attr("src");
                let username = $(item).find(".user-info .username").html();
                let icons = $(item).find(".dynamic-multi-img-container .dynamic-multi-img");
                let title = $(item).find(".dynamic-album-desc").html();
                let zan = $(item).find(".like-action .detail-text").html();
                let collect = $(item).find(".favorite-action .detail-text").html()
                let arr = [];
                icons.each((i,v)=>{
                    let img = $(v).attr("src");
                    arr.push(img);
                })

                links.push({
                    avatar:avatar,
                    username:username,
                    icons:arr,
                    title,
                    zan,
                    collect
                })
            })
        }
        return links;
       
    })
    browser.close();
    return res;
}
module.exports = run;